package com.springboot.service.impl;

import com.springboot.mapper.DoctorAppointSetMapper;
import com.springboot.mapper.DoctorFieldFormMapper;
import com.springboot.mapper.DoctorInfoFormMapper;
import com.springboot.model.DoctorAppointSet;
import com.springboot.model.DoctorFieldForm;
import com.springboot.model.DoctorInfoForm;
import com.springboot.service.PatientOrderViewService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.sql.Date;
import java.util.ArrayList;

@Service
public class PatientOrderViewServiceImpl implements PatientOrderViewService {
    @Autowired
    DoctorFieldFormMapper doctorFieldFormMapper ;

    @Autowired
    DoctorInfoFormMapper doctorInfoFormMapper;

    @Autowired
    DoctorAppointSetMapper doctorAppointSetMapper;

    @Override
    public ArrayList<DoctorFieldForm> findDoctorsByField(String field) {
        ArrayList<DoctorFieldForm> doctorFieldForm = doctorFieldFormMapper.selectByField(field);
        return doctorFieldForm;
    }

    @Override
    public ArrayList<DoctorFieldForm> findAllDoctorField() {
        ArrayList<DoctorFieldForm> doctorFieldForms = doctorFieldFormMapper.selectAll();
        return doctorFieldForms;
    }

    @Override
    public DoctorInfoForm findDoctorsById(Integer id){
        DoctorInfoForm doctorInfoForm = new DoctorInfoForm();
        try{
            doctorInfoForm = doctorInfoFormMapper.selectByPrimaryKey(id);
        }
        catch (Exception e)
        {
            e.printStackTrace();
        }
        return doctorInfoForm;
    }

    @Override
    public ArrayList<DoctorAppointSet> findOrderTimeByDoctorId(Integer id) {
        ArrayList<DoctorAppointSet> doctorAppointSets = doctorAppointSetMapper.selectByDoctorId(id);
        return doctorAppointSets;
    }

    /*
     * @ description:根据医生姓名或者职称查找
     * @ param      :[searchText]
     * @ return     :java.util.ArrayList<com.springboot.model.DoctorInfoForm>
     * @ date       :2020/12/27

    */
    @Override
    public ArrayList<DoctorInfoForm> findDoctorInfoFormByNameOrRank(String searchText) {

        ArrayList<DoctorInfoForm> doctorInfoForms = new ArrayList<>();
        try {
            doctorInfoForms = doctorInfoFormMapper.selectByRankOrName(searchText);
        }
        catch (Exception e)
        {
            System.out.println("PatientOrderViewServiceImpl 出错");
            System.out.println("查找为空");
        }
        return doctorInfoForms;
    }

    @Override
    public DoctorFieldForm findDoctorFieldByDoctorId(Integer doctorId) {
        DoctorFieldForm doctorFieldForm = new DoctorFieldForm();
        try {
            doctorFieldForm = doctorFieldFormMapper.selectDoctorFieldById(doctorId);
        }
        catch (Exception e)
        {
            System.out.println("PatientOrderViewServiceImpl 出错");
            System.out.println("findDoctorFieldByDoctorId 出错");
        }
        return doctorFieldForm;
    }

}
